<template>
	<el-dialog title="站内信发送" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="消息标题" prop="smsTitle">
				<el-input v-model="form.smsTitle" placeholder="消息标题" rows="4"></el-input>
			</el-form-item>
			<el-form-item label="接收人" prop="toUser">
				<select-user-dialog v-model:accountId="form.toUser" :mode="true"/>
			</el-form-item>
			<el-form-item label="消息内容" prop="smsContent">
				<el-input type="textarea" v-model="form.smsContent" placeholder="消息内容" rows="4"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">发 送</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectUserDialog from "@/views/module/selectUserDialog";
export default {
	emits: ['success', 'closed'],
	components: {
		selectUserDialog
	},
	data() {
		return {
			dialog: {
				isShow: false
			},
			visible: false,
			isSaveing: false,
			isShowMsg: false,
			form: {
				smsTitle:'',
				toUser: '',
				smsContent:''
			},
			rules: {
				smsTitle: [
					{required: true, message: '消息标题不能为空', trigger: 'blur'}
				],
				toUser: [
					{required: true, message: '请选择消息接收人员', trigger: 'blur'}
				],
				smsContent:[
					{required: true, message: '消息内容不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		submit() {
			if(this.form.toUser=="@all")
			{
				this.$alert("您不能全局发送站内信！", "提示", {type: 'error'});
				return;
			}
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {

					this.isSaveing = true;
					var res = await this.$API.system.sms.sendSms.post(this.form);
					if (res.code == 200) {
						this.isSaveing = false;
						this.$emit('success')
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
	}
}
</script>

<style>
</style>
